home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #2
/
Amiga Plus CD - 2004 - No. 02.iso
/
AmiSoft
/
Util
/
cli
/
Entries.lha
/
Entries
/
Entries.s
< prev
next >
Wrap
Text File
|
2003-12-26
|
22KB
|
882 lines
*****************************************************************************
* *
* PROGRAM: Entries *
* VERSION: 1.7 *
* SOURCE CODE: 29 (26.12.03) *
* DATE: 2.7.2003 - 22.7.2003 *
* LANGUAGE: Assembler (DevPac V3.14) *
* SYSTEM: A1200 KS 40.68 WB 40.42 2MB chip 64MB fast 68030/50mhz *
* *
* AUTHOR: Joerg Riemer 14167 Berlin/SchottmuellerStr.107/Germany *
* EMAIL: joerg_riemer@freenet.de / mission@cs.tu-berlin.de *
* *
* COMMENT: *
* *
* TEMPLATE: PATTERN,ALL/S,NOSTAT/S,MARKEMPTY/S,QUICK/S,LARGESTFILE/S *
* *
*****************************************************************************
* opt d+,ow2-
BSS_Section set 1
*****************************************************************************
output ram:Entries
************************************************ exec definitions ***********
_LVOOpenLibrary equ -552
_LVOCloseLibrary equ -414
************************************************ dos definitions ************
_LVOWrite equ -048
_LVOOutput equ -060
_LVOLock equ -084
_LVOUnLock equ -090
_LVOInfo equ -114
_LVOIoErr equ -132
_LVOFPutC equ -312
_LVOFPuts equ -342
_LVOSetIoErr equ -462
_LVOPrintFault equ -474
_LVOIsFileSystem equ -708
_LVOReadArgs equ -798
_LVOFreeArgs equ -858
_LVOMatchFirst equ -822
_LVOMatchNext equ -828
_LVOMatchEnd equ -834
_LVOVPrintf equ -954
ap_BreakBits equ $008
ap_Flags equ $010
ap_Strlen equ $012
ap_Info equ $014
fib_DirEntryType equ $004
fib_EntryType equ $078
fib_Size equ $07C
fib_NumBlocks equ $080
RDA_SIZEOF equ $020
RDA_ExtHelp equ $018
APB_DOWILD equ $000
APB_ITSWILD equ $001
APB_DODIR equ $002
APB_DIDDIR equ $003
APB_DODOT equ $005
ACCESS_READ equ -2
SIGBREAKB_CTRL_C equ $00C
SIGBREAKB_CTRL_D equ $00D
SIGBREAKB_CTRL_E equ $00E
SIGBREAKB_CTRL_F equ $00F
************************************************ icon definitions ***********
_LVOGetDiskObject equ -078
_LVOPutDiskObject equ -084
_LVOFreeDiskObject equ -090
WBPROJECT equ $004
do_Type equ $030
do_DefaultTool equ $032
************************************************ bss datas ******************
Anchorpath rs.b 280 ;size_of anchorpath
PathName rs.b 256 ;size_of ap_strlen (pathname)
rs.l 1 ;eof
BFName rs.b 256 ;path/filename biggest file
DOSBase rs.l 1 ;ptr. base of library
ArgArray rs.l 0 ;argarray
Pattern rs.l 1 ;argarray ptr. pattern
All rs.l 1 ;flag (print subdir entries)
NoStat rs.l 1 ;flag (don't print result)
MarkEmpty rs.l 1 ;flag (mark empty files)
Quick rs.l 1 ;flag (don't print entries)
BiggestFile rs.l 1 ;flag (print biggest file)
RDArgs rs.l 1 ;ptr. rdargs structure
RCode1 rs.l 1 ;errorcode -> rc
RCode2 rs.l 1 ;errorcode -> result2
FCount rs.l 2 ;# of files
EFiles rs.l 2 ;# of empty files
BigFile rs.l 2 ;# of files with extensions
FileSize rs.l 2 ;filesize total
HBlocks rs.l 2 ;# of headerblocks
DBlocks rs.l 2 ;# of datablocks
EBlocks rs.l 2 ;# of extensionblocks
DCount rs.l 2 ;# of directories
TotalBlocks rs.l 2 ;# of total blocks
BlockSize rs.l 2 ;physical blocksize
TotalSize rs.l 2 ;total size used
BFSize rs.l 2 ;size of biggest file
InfoData rs.l 0 ;InfoData returned by Info()
NumSoftErrs rs.l 1
UnitNum rs.l 1
DiskState rs.l 1
Blocks rs.l 1
BlocksUsed rs.l 1
BytesPerBlock rs.l 1
DiskType rs.l 1
VolumeNode rs.l 1
InUse rs.l 1
ExtSize rs.l 1 ;extension size in bytes
ExtBlocks rs.l 1 ;# of ext. entries per block
NoSize rs.l 1 ;flag (curr. file is empty)
LEDBit rs.l 1 ;powerled status
RDAStruct rs.b RDA_SIZEOF ;rdargs data structure
BSS_Size rs.b 0 ;bss_size over all
*****************************************************************************
Start movem.l D1-D7/A0-A6,-(SP) ;save registers
if BSS_Section ;check assembler condition
movea.l Start-4(pc),A5 ;get bss_section
addq.l #1,A5 ;skip pointer (next segment)
adda.l A5,A5 ;convert bpcl_pointer
adda.l A5,A5 ;to real_address
elseif ;otherwise
lea DataBase(pc),A5 ;set working area
endc ;end condition
************************************************ open libraries *************
moveq #20,D0 ;failat level
move.l D0,RCode1(A5) ;preset error (no library)
movea.l 4.w,A6 ;set EXEC to call a function
moveq #37,D0 ;required library version
lea DOSName(pc),A1 ;set library name
jsr _LVOOpenLibrary(A6) ;use EXEC to (openlibrary)
move.l D0,DOSBase(A5) ;save base
beq.b CloseLibs ;branch if not open
*****************************************************************************
bsr.b Main
************************************************ close libraries ************
CloseLibs movea.l 4.w,A6 ;set EXEC to call a function
CloseDOS move.l DOSBase(A5),D1 ;get base_ptr
beq.b ExitDOS ;branch when not open
movea.l D1,A1 ;set base_ptr
jsr _LVOCloseLibrary(A6) ;use EXEC to (closelibrary)
ExitDOS move.l RCode1(A5),D0 ;set returncode
movem.l (SP)+,D1-D7/A0-A6 ;restore registers
rts ;go back (shell)
*****************************************************************************
DOSName dc.b "dos.library",0
*****************************************************************************
version dc.b "$VER: Entries 1.7 29 (26.12.2003) by joerg riemer jul'03",0
*****************************************************************************
cnop 0,4
*****************************************************************************
Main clr.l RCode1(A5) ;clear returncode
bsr ReadArgs ;q0 read user_arguments
bsr CheckArgs ;q0 check user_arguments
bsr IsFileSystem ;q0 check for valid filesystem
bsr InitAPath ;prepare anchorpath
bsr MatchFirst ;search for filename
bsr GetDiskInfo
bsr GetLEDBit
*****************************************************************************
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOOutput(A6) ;search output_handle
move.l D0,D7 ;save output
************************************************
lea PathName(A5),A2 ;get filename to print
lea Anchorpath(A5),A3 ;get anchorpath structure
lea ap_Info(A5),A4 ;get fileinfoblock
btst #APB_ITSWILD,ap_Flags(A5)
beq.b .skip
bchg #1,$bfe001
.skip tst.b Quick(A5) ;do all Quick ?
bne DoQuick ;branch if so
************************************************
.Loop moveq #1,D2
tst.l fib_DirEntryType(A4) ;type = dir ?
bmi.b .skip1 ;branch if not
bclr #APB_DIDDIR,ap_Flags(A5)
bne .MatchNext
add.l D2,DCount(A5) ;# of directories
bchg #1,$bfe001
tst.l All(A5)
beq.b .skip2
bset #APB_DODIR,ap_Flags(A5)
bra.b .skip2
.skip1 add.l D2,HBlocks(A5) ;# of headerblocks
move.l fib_Size(A4),D0
seq NoSize(A5)
beq.b .skip2
tst.l BiggestFile(A5)
beq.b .skip4
cmp.l BFSize(A5),D0
blt.b .skip4
move.l D0,BFSize(A5)
move.l A2,A0
lea BFName(A5),A1
.copyname move.l (A0)+,(A1)+ ;copies max. 256 bytes
bne.b .copyname
.skip4 add.l D2,FCount(A5) ;# of files
add.l D2,TotalBlocks(A5)
add.l D0,FileSize(A5)
cmp.l ExtSize(A5),D0
ble.b .skip3
add.l D2,BigFile(A5)
move.l ExtSize(A5),D1
move.l ExtBlocks(A5),D2
neg.l D2
.CalcExtBlocks addq.l #1,EBlocks(A5)
add.l ExtBlocks(A5),D2
sub.l D1,D0
bcc.b .CalcExtBlocks
add.l D2,DBlocks(A5)
add.l D2,TotalBlocks(A5)
add.l D1,D0
.skip3 move.l BytesPerBlock(A5),D1
moveq #0,D2
.CalcFileBlocks addq.l #1,D2
sub.l D1,D0
bcc.b .CalcFileBlocks
add.l D2,DBlocks(A5)
.skip2 add.l D2,TotalBlocks(A5)
******************* print path/filename ********
.PrintFName move.l D7,D1 ;set output
move.l A2,D2 ;get filename to print
jsr _LVOFPuts(A6) ;use dos to fputs
************************************************
tst.b NoSize(A5)
beq.b .PrintNLine
tst.b MarkEmpty(A5)
beq.b .PrintNLine
move.l D7,D1
lea EString(pc),A1
move.l A1,D2
jsr _LVOFPuts(A6)
******************* print newline character ****
.PrintNLine move.l D7,D1 ;set output
moveq #$A,D2 ;set char. to print
jsr _LVOFPutC(A6) ;use dos to fputc
******************* matchnext pattern **********
.MatchNext move.l A3,D1 ;get anchorpath structure
jsr _LVOMatchNext(A6) ;use dos to matchnext
move.l D0,D1 ;get return_code
beq .Loop ;loop again when ok
bra Quit2
*****************************************************************************
DoQuick
.Loop moveq #1,D2
tst.l fib_DirEntryType(A4) ;type = dir ?
bmi.b .skip1 ;branch if not
bclr #APB_DIDDIR,ap_Flags(A5)
bne .MatchNext
add.l D2,DCount(A5) ;# of directories
bchg #1,$bfe001
tst.l All(A5)
beq.b .skip2
bset #APB_DODIR,ap_Flags(A5)
bra.b .skip2
.skip1 add.l D2,HBlocks(A5) ;# of headerblocks
move.l fib_Size(A4),D0
seq NoSize(A5)
beq.b .skip2
tst.l BiggestFile(A5)
beq.b .skip4
cmp.l BFSize(A5),D0
blt.b .skip4
move.l D0,BFSize(A5)
move.l A2,A0
lea BFName(A5),A1
.copyname move.l (A0)+,(A1)+ ;copies max. 256 bytes
bne.b .copyname
.skip4 add.l D2,FCount(A5) ;# of files
add.l D2,TotalBlocks(A5)
add.l D0,FileSize(A5)
cmp.l ExtSize(A5),D0
ble.b .skip3
add.l D2,BigFile(A5)
move.l ExtSize(A5),D1
move.l ExtBlocks(A5),D2
neg.l D2
.CalcExtBlocks addq.l #1,EBlocks(A5)
add.l ExtBlocks(A5),D2
sub.l D1,D0
bcc.b .CalcExtBlocks
add.l D2,DBlocks(A5)
add.l D2,TotalBlocks(A5)
add.l D1,D0
.skip3 move.l BytesPerBlock(A5),D1
moveq #0,D2
.CalcFileBlocks addq.l #1,D2
sub.l D1,D0
bcc.b .CalcFileBlocks
add.l D2,DBlocks(A5)
.skip2 add.l D2,TotalBlocks(A5)
************************************************
tst.b NoSize(A5)
beq.b .MatchNext
tst.b MarkEmpty(A5)
beq.b .MatchNext
not.b NoSize(A5)
******************* print path/filename ********
.PrintFName move.l D7,D1 ;set output
move.l A2,D2 ;get filename to print
jsr _LVOFPuts(A6) ;use dos to fputs
******************* print newline character ****
.PrintNLine move.l D7,D1 ;set output
moveq #$A,D2 ;set char. to print
jsr _LVOFPutC(A6) ;use dos to fputc
******************* matchnext pattern **********
.MatchNext move.l A3,D1 ;get anchorpath structure
jsr _LVOMatchNext(A6) ;use dos to matchnext
move.l D0,D1 ;get return_code
beq .Loop ;loop again when ok
*****************************************************************************
Quit2 cmp.w #232,D1 ;check for 'no more entries'
bne Error5 ;branch if not
move.l #205,D1 ;preset 'object not found'
move.l FCount(A5),D0 ;found some files ?
or.l DCount(A5),D0 ;found some dirs ?
beq Error5 ;branch if not
tst.l NoStat(A5) ;print statistic ?
bne.b Quit0 ;
bsr.b PrintResult ;print some information
Quit0 bsr MatchEnd ;close matchnext() function
bsr FreeArgs ;free memory (readargs)
bsr SetLEDBit
rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
GetLEDBit move.b $bfe001,D0
andi.b #%00000010,D0
move.b D0,LEDBit(A5)
rts
*****************************************************************************
cnop 0,4
*****************************************************************************
SetLEDBit move.b LEDBit(A5),D1
move.b $bfe001,D0
andi.b #%11111101,D0
eor.b D1,D0
move.b D0,$bfe001
rts
*****************************************************************************
cnop 0,4
************************************************ print result **************
PrintResult move.l TotalBlocks(A5),D0 ;get # of blocks used
move.l BlockSize(A5),D1 ;get blocksize
moveq #0,D2 ;prepare register
.CalcTSize add.l D1,D2 ;calc. totalsize
subq.l #1,D0 ;calc. totalsize
bne.b .CalcTSize ;calc. totalsize
move.l D2,TotalSize(A5) ;save result
lea RString00(pc),A3 ;get formatstring
lea -12(A3),A3 ;init. offset
lea DecTab(pc),A0 ;get count of digits
.loop lea 12(A3),A3 ;get count of digits
cmp.l (A0)+,D2 ;get count of digits
blt.b .loop ;get count of digits
************************************************
move.l HBlocks(A5),D0 ;calc. empty files
sub.l FCount(A5),D0 ;calc. empty files
move.l D0,EFiles(A5) ;calc. empty files
************************************************
PrintResult1 lea RString01(pc),A4 ;get first string
lea FCount(A5),A2 ;get ptr. (array of values)
.loop move.l A3,D1 ;set formatstring
move.l A2,D2 ;set datastream
move.l A4,4(A2) ;set stringptr.
jsr _LVOVPrintf(A6) ;use dos to VPrintf
lea 8(A2),A2 ;get next array of values
lea 28(A4),A4 ;get next string
tst.b (A4) ;anything to print
bne.b .loop ;do if so
tst.l BiggestFile(A5)
beq.b .skip
tst.l BFSize(A5)
beq.b .skip
addq.l #1,A4
move.l A3,D1 ;set formatstring
move.l A2,D2 ;set datastream
move.l A4,4(A2) ;set stringptr.
jsr _LVOVPrintf(A6) ;use dos to VPrintf
******************* print path/filename ********
.PrintFName move.l D7,D1 ;set output
lea BFName(A5),A2
move.l A2,D2 ;get filename to print
jsr _LVOFPuts(A6) ;use dos to fputs
******************* print newline character ****
.PrintNLine move.l D7,D1 ;set output
moveq #$A,D2 ;set char. to print
jsr _LVOFPutC(A6) ;use dos to fputc
.skip rts ;go back
*****************************************************************************
DecTab dc.l 1000000000
dc.l 100000000
dc.l 10000000
dc.l 1000000
dc.l 100000
dc.l 10000
dc.l 1000
dc.l 100
* dc.l 10
* dc.l 1
RString00 dc.b " %13lU %s",$A,0,0
dc.b " %11lU %s",$A,0,0
dc.b " %10lU %s",$A,0,0
dc.b " %9lU %s ",$A,0,0
dc.b " %7lU %s ",$A,0,0
dc.b " %6lU %s ",$A,0,0
dc.b " %5lU %s ",$A,0,0
dc.b " %3lU %s ",$A,0,0
RString01 dc.b "files ",0,0,0
RString02 dc.b "empty files ",0,0,0
RString03 dc.b "files with extension ",0,0,0
RString04 dc.b "bytes filesize total ",0,0,0
RString05 dc.b "headerblocks ",0,0,0
RString06 dc.b "datablocks ",0,0,0
RString07 dc.b "extensionblocks ",0,0,0
RString08 dc.b "directories ",0,0,0
RString09 dc.b "diskblocks used total ",0,0,0
RString10 dc.b "bytes per block ",0,0,0
RString11 dc.b "bytes used total ",0,0,0,0
RString12 dc.b "bytes for largest file ",0,0,0
EString dc.b " EMPTY-FILE",0
*****************************************************************************
cnop 0,4
************************************************ free memory matchfirst/next
MatchEnd lea Anchorpath(A5),A1 ;get anchorpath structure
tst.l (A1)
beq.b .skip
move.l A1,D1 ;prepare matchend
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOMatchEnd(A6) ;use dos for matchend
.skip rts ;go back
*****************************************************************************
cnop 0,4
************************************************ matchfirst pattern *********
MatchFirst move.l Pattern(A5),D1 ;get user pattern/file
lea Anchorpath(A5),A2 ;get anchorpath
move.l A2,D2 ;used for matching
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOMatchFirst(A6) ;use dos for matchfirst
move.l D0,D1 ;get returncode
beq.b .skip ;branch if ok
addq #4,SP ;clear return_address
pea Quit2(pc) ;set new one
.skip rts ;go back
*****************************************************************************
cnop 0,4
************************************************ prepare anchorpath *********
InitAPath moveq #00,D0 ;prepare register
bset #SIGBREAKB_CTRL_C,D0 ;do break on <CTRL><C> !!!
move.l D0,ap_BreakBits(A5) ;set bit
bset #APB_DOWILD,ap_Flags(A5)
* bset #APB_DODIR,ap_Flags(A5)
* bset #APB_DODOT,ap_Flags(A5)
move.w #256,ap_Strlen(A5) ;set length of string_buffer
rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
IsFileSystem movea.l Pattern(A5),A1
move.l A1,D1
.compare cmp.b #":",(A1)+
beq.b .GetFileSystem
tst.b (A1)
bne.b .compare
rts
.GetFileSystem movea.l A1,A2
move.b (A1),D7
clr.b (A1)
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOIsFileSystem(A6) ;use DOS to get filesystem
move.b D7,(A2)
tst.l D0 ;get returncode
beq Error7 ;branch if ok
rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
GetDiskInfo lea PathName(A5),A1 ;get name
move.l A1,D1 ;set name
moveq #ACCESS_READ,D2 ;set type
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOLock(A6) ;use DOS to (lock) file
move.l D0,D7 ;save lock (temp.)
move.l D0,D1 ;set lock
lea InfoData(A5),A2 ;get parameterblock
move.l A2,D2 ;set parameterblock
jsr _LVOInfo(A6) ;read diskinfo
move.l D7,D1 ;set lock
jsr _LVOUnLock(A6) ;unlock file
move.l BytesPerBlock(A5),D0
move.l D0,D2
move.l D0,D3
moveq #0,D1
bset #9,D1
.sub sub.l D1,D0
bcc.b .sub
neg.l D0
cmp.l D0,D1
beq.b .saveBS
add.l D0,D2
.saveBS move.l D2,BlockSize(A5)
sub.l #224,D2
lsr.l #2,D2
move.l D2,ExtBlocks(A5)
bclr #9,D1
moveq #1,D0
.add add.l D3,D1
sub.l D0,D2
bne.b .add
move.l D1,ExtSize(A5)
rts
*****************************************************************************
cnop 0,4
*********************************************** read user arguments *********
ReadArgs lea ExtHelp(pc),A0 ;get rdargs_exthelp
lea Template(pc),A1 ;get template
lea ArgArray(A5),A2 ;get arg_array
lea RDAStruct(A5),A3 ;get rdargs data structure
move.l A0,RDA_ExtHelp(A3) ;set extented help
move.l A1,D1 ;set arg_template
move.l A2,D2 ;set array
move.l A3,D3 ;set rdargs data structure
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOReadArgs(A6) ;use dos to readargs
move.l D0,RDArgs(A5) ;save returncode
beq Error1 ;branch on wrong args
rts ;else, go back
*****************************************************************************
cnop 0,4
************************************************ check arguments ************
CheckArgs moveq #116,D1 ;"required args miss..."
move.l Pattern(A5),D0 ;pattern there ?
or.l All(A5),D0 ;all-flag set ?
beq.b Error6 ;branch if not
rts ;go back
*****************************************************************************
cnop 0,4
************************************************ free argument buffer *******
FreeArgs move.l RDArgs(A5),D1 ;get arg_structure
beq.b .skip ;branch if not set
move.l DOSBase(A5),A6 ;set dos_base
jsr _LVOFreeArgs(A6) ;use dos to freeargs
.skip rts ;go back
*****************************************************************************
cnop 0,4
************************************************ error handling *************
Error7 move.l #225,D1 ;result_2 "not a valid dos.."
addq #4,SP ;clear return_address
bra.b Error5
************************************************
cnop 0,4
************************************************
Error6 move.l D1,RCode2(A5) ;set errorcode
addq.l #4,SP ;clear return_address
bra.b Error ;print error
************************************************
cnop 0,4
************************************************
Error5 move.l D1,RCode2(A5) ;set errorcode
pea Quit0(pc) ;set return_address
bra.b Error ;print error
************************************************
cnop 0,4
************************************************
Error2 addq #4,SP ;clear return_address
pea Quit0(pc) ;set new one
bra.b Error0 ;print error
************************************************
cnop 0,4
************************************************
Error1 addq #4,SP ;clear return_address
************************************************
Error0 movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOIoErr(A6) ;use dos to get ioerr
move.l D0,RCode2(A5) ;save as pr_result2
************************************************
Error move.l RCode2(A5),D1 ;get errorcode
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOSetIoErr(A6) ;use dos to set pr_result2
* tst.b Quick(A5) ;do all Quick ?
* bne.b .SetRCode1 ;branch if so
move.l RCode2(A5),D1 ;get errorcode
moveq #0,D2
cmp.w #304,D1 ;"***Break"
beq.b .skip
lea Header(pc),A2 ;get head_text 'ERROR:'
move.l A2,D2 ;set header
.skip jsr _LVOPrintFault(A6) ;use dos to printfault
.SetRCode1 moveq #5,D0 ;set returncode rc=warn
move.l D0,RCode1(A5) ;save
rts ;go back
*****************************************************************************
ExtHelp
dc.b $A
dc.b "Entries V1.6 by Joerg Riemer Aug'03",$A
dc.b $A
dc.b " PATTERN/A: path/pattern to examine",$A
dc.b " ALL/S: examine all sub-directories",$A
dc.b " NS=NOSTAT/S: don't print statistic",$A
dc.b " ME=MARKEMPTY/S: mark/print path/filename of empty files",$A
dc.b " Q=QUICK/S: don't print any path/filename",$A
dc.b " LF=LARGESTFILE/S: print path/filename of largest file",$A
dc.b $A
Template dc.b "PATTERN/A,ALL/S,NS=NOSTAT/S,ME=MARKEMPTY/S,Q=QUICK/S,LF=LARGESTFILE/S",0
Header dc.b "ERROR",0
*****************************************************************************
if BSS_Section
SECTION MatchTest_bss,BSS
elseif
cnop 0,4
endc
*****************************************************************************
DataBase ds.b BSS_Size
end of source **************************************************************